'use strict'

let Koa = require('koa')
let router = require('koa-router')()
let bodyParser = require('koa-bodyparser')

let routes = require('./router')

let app = new Koa()

app.use(bodyParser())
app.use(router.routes())

for(var r in routes){
    router.get(r,router[r])
}

// router.get('/', async (ctx, next) => {
//     ctx.body = 'This is my index'
// })

// router.get('/proFile', async (ctx, next) => {
//     ctx.body = `<form action="" method="POST">
//     <label>username:</label>李兆龙<br>
//     <label>Icon:</label> 888BTS <br>
//     <textarea name="Introcuce" id="" cols="50" rows="10">个人简介</textarea>
// </form>`
// })

// router.get('/login', async (ctx, next) => {
//     ctx.body = `
//     <h1>This is LoginPanel</h1>
//     <form action="/Login" method="POST">
//     <label>username:</label><input type="text" name="username"><br>
//     <label>password:</label><input type="password" name="password"><br>
//     <input type="submit" value="Login">
//     </form>
//     `
// })

// router.post('/loginDone', async (ctx, next) => {
//     let username = ctx.request.body.username || ''
//     let password = ctx.request.body.password || ''
//     console.log(username);
//     console.log(password);

//     if (username === "李兆龙" && password === '1050621252') {
//         ctx.body = `<h1>Welcome to your Profile</h1>`
//     } else {
//         ctx.body = `<a href="/Login">Try again</a>`
//     }
// })

let port = 8888
app.listen(port)

console.log(`Server is running at http://localhost:${port}`);